﻿using System;
using System.Net.Http;
using System.Windows;
using BookSourceVerification.execute;
using Microsoft.Extensions.DependencyInjection;
using NLog;

namespace BookSourceVerification
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public static string? FilePath;
        public static IServiceProvider? ServiceProvider { get; private set; }

        protected override void OnStartup(StartupEventArgs e)
        {
            var serviceCollection = new ServiceCollection();
            ConfigureServices(serviceCollection);
            ServiceProvider = serviceCollection.BuildServiceProvider();
            base.OnStartup(e);
            // 获取命令行参数
            string[] args = Environment.GetCommandLineArgs();

            if (args.Length > 1)
            {
                FilePath = args[1];
            }
        }

        private static void ConfigureServices(IServiceCollection serviceCollection)
        {
            serviceCollection.AddHttpClient<HttpClient>(client =>
            {
                client.Timeout = TimeSpan.FromMilliseconds(1000);
            });
            serviceCollection.AddTransient(typeof(MainWindow));
        }
    }
}